from openai import OpenAI
from dotenv import load_dotenv
import os

load_dotenv()

client = OpenAI(
	base_url="https://ai.gitee.com/v1",
	api_key=os.getenv("api_key"),
)

response = client.audio.speech.create(
	input="你好，这里是 Gitee AI 模型广场中的语音合成类模型，我会根据您的需求生成符合预期的模型", # 需要替换为实际的文本输入内容
	model="fish-speech-1.5",
	extra_body={
		"top_p": 0.7,
		"repetition_penalty": 1.2,
		"temperature": 0.7,
		"max_new_tokens": 2048,
		"chunk_length": 200,
        "reference_audio_url": "https://example.com/reference_audio.mp3",  # 需要替换为实际的参考音频 URL
        "reference_text": "这是一个参考文本，用于指导模型生成更自然的语音。",
	},
	voice="alloy",
)
output_dir = "audio_output"
os.makedirs(output_dir, exist_ok=True)

output_file = os.path.join(output_dir, "generated_speech.mp3")
# 可根据实际目录进行修改
with open(output_file, "wb") as f:
    f.write(response.content)

print(f"✅ Voice generation successful! Save path: {output_file}")
print(f"🔊 File size: {len(response.content)//1024} KB")